#include <linux/module.h>
#include <linux/configfs.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/iio/imu/icm42686.h>

extern struct iio_dev *icm42686dev_iio;
extern struct icm42686 *icm42686_bottom_dev;

static float gyro_data2float(  u8 data_h,  u8 data_l )
{
	union {
		s16 data_short;
		u16 data_ushort;
	} us2s;

	us2s.data_ushort = (((u16)data_h) << 8) | data_l;

	return (float)us2s.data_short;	/* pgr0872 */
}

static float icm42686_accel_data_gravity( const u8 data_h, const u8 data_l )
{
	float f_val;
	float accel_1g_count;


	accel_1g_count = 16384.0;	// typ.


	f_val = gyro_data2float( data_h, data_l );
	
	return (f_val / accel_1g_count);
}

static void test_imu(void)
{
	struct icm42686_data imu = {0};

	icm42686_get_data_front(icm42686dev_iio, &imu);
}

static void test_imu2(void)
{
	struct icm42686_data imu = {0};

	icm42686_get_data_bottom(icm42686_bottom_dev, &imu);
}


static int __init hello_init(void)
{
	#if 0
	icm42686_accel_data_gravity(0x11, 0x22)  * ( 3.1415926 / 180 );
	icm42686_accel_data_gravity(h, l);	// kernel panic
	#endif

	test_imu();
	test_imu2();

	printk("aaaaaaaabbbbaaaaaaaaaaaaaaaaa\n");

    return 0;
}

static void __exit hello_exit(void)
{
    printk("Goodbye,cruel world!\n");
}

module_init(hello_init);
module_exit(hello_exit);

MODULE_AUTHOR("aaaa");
MODULE_LICENSE("Dual BSD/GPL");
